package cz.data.domain.metadata.service;

import cz.data.common.support.db.DbType;
import cz.data.domain.driver.rpc.ElasticsearchDriverFeign;
import cz.data.domain.driver.rpc.IDriverFeign;
import cz.data.domain.driver.rpc.JdbcDriverFeign;
import cz.data.domain.driver.rpc.KafkaDriverFeign;
import cz.data.domain.driver.rpc.MongoDriverFeign;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class RemoteDriverService {

    @Resource
    JdbcDriverFeign jdbcDriverFeign;
    @Resource
    KafkaDriverFeign kafkaDriverFeign;
    @Resource
    MongoDriverFeign mongoDriverFeign;
    @Resource
    ElasticsearchDriverFeign elasticsearchDriverFeign;

    public IDriverFeign getDriverFeign(String dbType) {
        return getDriverFeign(DbType.getDbType(dbType));
    }

    public IDriverFeign getDriverFeign(DbType dbType) {
        switch (dbType) {
            case MYSQL:
            case MARIADB:
            case ORACLE:
            case ORACLE_12C:
            case SQL_SERVER:
            case SQL_SERVER2008:
            case POSTGRE_SQL:
            case VERTICA:
                return jdbcDriverFeign;
            case ELASTICSEARCH:
                return elasticsearchDriverFeign;
            case KAFKA:
                return kafkaDriverFeign;
            case MONGODB:
                return mongoDriverFeign;
            default:
                throw new UnsupportedOperationException("未适配数据源类型:" + dbType);
        }
    }
}
